/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.controller;

import com.bayu.services.dao.PfrekapDao;
import com.bayu.services.entity.Pfrekap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author Bayu
 */

@Controller
@RequestMapping("/pfrekap-update.htm")
public class PfRekapUpdate {
    PfrekapDao pfrekapDao;
    @Autowired
    private void setPfDao(PfrekapDao pfrekapDao){
      this.pfrekapDao = pfrekapDao;
    }

    @RequestMapping(method = RequestMethod.GET)
    public void displayForm(ModelMap map,String id){
        List list = this.pfrekapDao.getById(Long.parseLong(id));
        map.addAttribute("data", list);
    }

    @RequestMapping(method = RequestMethod.POST)
    public String proccessForm(@ModelAttribute("Pfrekap") Pfrekap pf , BindingResult result,ModelMap map, String date,HttpServletRequest req){
            

            String id = req.getParameter("id");

            if(id!=null){
                 pf.setId(Long.parseLong(id));
                 this.pfrekapDao.update(pf);
                 return "redirect:view-pfrekap-data.htm?msg=Data has been updated";
            }else{
                return "redirect:pfrekap-update.htm";
            }





    }
}
